Skip to content

Fix compatibility with min()/max() macros - #399

Merged
lemire merged 2 commits into
fastfloat:mainfrom
dg0yt:max
Aug 17, 2026
Merged

lemire merged 2 commits into
fastfloat:mainfrom
dg0yt:max

Conversation

@dg0yt

@dg0yt dg0yt commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

windows.h may define min() and max() macros. It is possible to guard against this on the consuming side. But this might get fragile with transitive dependencies. This PR suggests to avoid the problem in the headers.
Noticed while updating vcpkg ports (breaking build of opencv4 and opencv3).

@lemire

lemire commented Jul 23, 2026

Copy link
Copy Markdown
Member

Good.

@lemire
lemire merged commit 13ecd70 into fastfloat:main Aug 17, 2026
35 checks passed
@dg0yt
dg0yt deleted the max branch August 19, 2026 08:24
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
fast_float 8.3.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* New `chars_format::javascript` format ([ECMAScript DecimalLiteral](https://tc39.es/ecma262/#prod-DecimalLiteral)): like JSON, but the integer part may be empty (`.5`) and the fractional part may be empty (`5.`, `5.e3`); leading zeros, `inf` and `nan` are rejected. fastfloat/fast_float#407
* New `chars_format::javascript_sloppy` format: additionally accepts sloppy-mode `NonOctalDecimalIntegerLiteral` (`08.5` is 8.5). A legacy octal literal (`0775`) is rejected with the new `parse_error::legacy_octal_integer_part` so it can be parsed in base 8.
* Faster integer-part scanning (4-digit SWAR on GCC) and skipping the rounding-mode probe for long mantissas by @fcostaoliveira in fastfloat/fast_float#398
* Avoid old-style casts by @lemire in fastfloat/fast_float#405
* Fix compatibility with `min()`/`max()` macros by @dg0yt in fastfloat/fast_float#399
* Guard `is_space` against negative signed code units by @sahvx655-wq in fastfloat/fast_float#395
* docs: fix strtod function name in README by @latent-9 in fastfloat/fast_float#404

**Full Changelog**: fastfloat/fast_float@v8.2.10...v8.3.0
</pre>
  <p>View the full release notes at <a href="https://github.com/fastfloat/fast_float/releases/tag/v8.3.0">https://github.com/fastfloat/fast_float/releases/tag/v8.3.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!20258
@IRainman

Copy link
Copy Markdown

Hmm, this is an incorrect fix for the C++ project, because you can simply define
#define NOMINMAX -Macros min(a, b) and max(a, b)
before including windows.h ^^'

@lemire

lemire commented Oct 11, 2026

Copy link
Copy Markdown
Member

@IRainman We do not control how windows.h gets included.

@IRainman

Copy link
Copy Markdown

@IRainman We do not control how windows.h gets included.

Yes, but it's not your problem. All Windows developers should know about this. Furthermore, you can add a static assert if min or max is defined. These macros broke so many things, so it's not needed as a crutch like this.

@dg0yt

dg0yt commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

In a flat world, it might be okay to go for "the user must know, the user must fix it."

But the world of C++ isn't flat. fastfloat is a popular dependency in packages which are mixed in unforeseen ways. The user may not even know that he transitively includes fastfloat and windows.h. And every dependency in the chain may change the order of inclusion. A simple #define NOMINMAX in the user project simply does not solve the problem.

So this is the second best solution which can be done in a single place. The correct solution is to never put macros like min and max in a global namespace. But I wouldn't wait for windows.h to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants